<template>
	<view class="page">
		<!-- 地址 -->
		<view class="address-data" v-if="address.name">
			<view class="address-list" @click="toAddress">
				<view class="list">
					<text>{{address.name}}</text>
					<text>{{address.phone}}</text>
				</view>
				<view class="list">
					<text>{{address.site}}</text>
				</view>
				<view class="list">
					<text class="address">{{address.detailAddress}}</text>
				</view>

				<view class="list">
					<text class="tips">(如果快递不方便接收，您可以选择暂时寄存服务)</text>
				</view>
			</view>
			<view class="bar">
			</view>
		</view>
		<view v-else @click="toAddress">
			<u-empty text="请选择收货地址" mode="address"></u-empty>
		</view>
		<view class="goods-data">
			<view class="goods-title">
				<text>商品信息</text>
			</view>

			<view class="goods-list">
				<view class="list" v-for="(goods,index) in orderList" :key="index">
					<view class="thumb">
						<image :src="goods.indexUrl" mode=""></image>
					</view>
					<view class="item">
						<view class="title">
							<text class="name one-omit">{{goods.shopName}}</text>
							<!-- <text class="attr">颜色：灰色,XL</text> -->
						</view>
						<view class="price-number">
							<view class="price">
								<text class="min">￥</text>
								<text class="max">{{goods.price}}</text>
								<text class="min">.00</text>
							</view>
							<view class="number">
								<text>x {{goods.num}}</text>
							</view>
						</view>
						<view class="tag">
							<text>支持七天无理由退货</text>
						</view>
					</view>
				</view>
			</view>
			<view class="delivery">
				<div class="list">
					<view class="title">配送</view>
					<view class="content">
						<text>快递运输</text>
						<text class="iconfont icon-more"></text>
					</view>
				</div>
				<div class="list">
					<view class="title">运费险</view>
					<view class="content">
						<text>￥0.00</text>
						<text class="iconfont icon-check"></text>
					</view>
				</div>
				<div class="list">
					<view class="title">留言</view>
					<view class="content">
						<input type="text">
						<!-- <u-input type="text" /> -->
					</view>
				</div>
			</view>
		</view>
		<!-- 优惠 -->
		<view class="discounts-data">
			<view class="discounts">
				<div class="list">
					<view class="title">发票</view>
					<view class="content">
						<text>不开发票</text>
						<text class="iconfont icon-more"></text>
					</view>
				</div>
			</view>
		</view>
		<!-- 订单金额 -->
		<view class="order-price">
			<view class="price-list">
				<view class="list">
					<view class="title">
						<text>商品金额</text>
					</view>
					<view class="price">
						<text>￥{{totalPrice}}.00</text>
					</view>
				</view>

				<view class="list">
					<view class="title">
						<text>运费</text>
					</view>
					<view class="price">
						<text class="highlight">+￥0.00</text>
					</view>
				</view>
				<view class="list">
					<view class="title">
						<text>运费险</text>
					</view>
					<view class="price">
						<text class="highlight">+￥0.00</text>
					</view>
				</view>
			</view>
		</view>
		<!-- 地址提示 -->
		<view class="address-tips" :style="scrollTop >= 100 ? '':'display:none'">
			<text>{{address.site+address.detailAddress}}</text>
		</view>
		<!-- 底部合计提交 -->
		<view class="footer-submit">
			<view class="price">
				<text class="min">￥</text>
				<text class="max">{{totalPrice}}</text>
				<text class="min">.00</text>
			</view>
			<view class="submit" @click="onSubmit">
				<u-modal v-model="show" @confirm="confirm" :content="where" :show-cancel-button="true" @cancel="cancel">
					<!-- 	<view class="slot-content">
						<rich-text :nodes="content"></rich-text>
					</view> -->
				</u-modal>
				<text>提交订单</text>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		components: {

		},

		data() {
			return {
				scrollTop: 0,
				src: 'https://api.ruhuashop.com//uploads/other/5df1e952e489f.png',
				tradeNo: '',
				orderList: [],
				totalPrice: '',
				show: false,
				address: {
					name: '',
					phone: '',
					site: '',
					detailAddress: ''
				}
			};
		},
		computed: {
			where() {
				return `请支付${this.totalPrice}元`
			}
		},
		onLoad(option) {
			this.tradeNo = option.tradeNo
			console.log(option);
			this.address.name = option.name
			this.address.phone = option.phone
			this.address.site = option.site
			this.address.detailAddress = option.detailAddress
			this.getOrderList()

		},
		onShow() {},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		methods: {
			//获取订单数据
			getOrderList() {
				uniCloud.callFunction({
					name: "getOrderInfo",
					data: {
						tradeNo: this.tradeNo
					}
				}).then(res => {
					this.orderList = res.result.data[0].goodsInOrder
					this.totalPrice = res.result.data[0].totalFee
				})
			},

			//提交订单
			onSubmit() {
				this.show = true

			},
			confirm() {
				console.log(12);
				const db = uniCloud.database();
				const collection = db.collection('order').where({
					tradeNo: this.tradeNo
				}).update({
					payStatus: 1
				})
				this.$u.toast('支付成功')
				//处理销量和库存
				uniCloud.callFunction({
					name: "handle-sales-stock",
					data: {
						_id: this.orderList[0]._id,
						handleNum: this.orderList[0].num
					}
				}).then(res => {

				})
				setTimeout(() => {
					this.$u.route({
						type: 'switchTab',
						url: '/pages/index/index'
					});
				}, 2000)
			},
			cancel() {
				this.$u.toast('未支付')
			},
			toAddress() {
				this.$u.route('/pages/address/address', {
					tradeNo: this.tradeNo
				});
			}

		}
	}
</script>

<style scoped lang="scss">
	.page {
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		// height: 100%;
		background-color: #f6f6f6;
		padding-bottom: 180rpx;
	}

	/* 地址 */
	.address-data {
		position: relative;
		padding: 10rpx 4%;
		background-color: #FFFFFF;
		border-radius: 0 0 20rpx 20rpx;
		overflow: hidden;

		.bar {
			position: absolute;
			left: 0;
			bottom: 0;
			width: 100%;
			height: 10rpx;
			background-color: #CCCCCC;
			background-image: linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
			background-size: 72rpx 72rpx;
		}

		.address-list {
			width: 100%;

			.list {
				display: flex;
				align-items: center;
				width: 100%;
				height: 60rpx;

				text {
					font-size: 24rpx;
					color: #555555;
					margin-right: 10rpx;
				}

				.address {
					font-size: 32rpx;
					color: #222222;
				}

				.tips {
					color: #fe3b0f;
				}
			}
		}
	}

	/* 商品 */
	.goods-data {
		padding: 10rpx 4%;
		background-color: #FFFFFF;
		border-radius: 20rpx;
		margin: 20rpx auto;

		.goods-title {
			display: flex;
			align-items: center;
			width: 100%;
			height: 80rpx;

			text {
				font-size: 26rpx;
				color: #222222;
			}
		}

		.goods-list {
			width: 100%;

			.list {
				display: flex;
				align-items: center;
				width: 100%;
				height: 200rpx;

				.thumb {
					display: flex;
					align-items: center;
					width: 30%;
					height: 100%;

					image {
						width: 160rpx;
						height: 160rpx;
						border-radius: 10rpx;
					}
				}

				.item {
					width: 70%;
					height: 160rpx;

					.title {
						display: flex;
						flex-direction: column;
						// justify-content: center;
						width: 100%;
						height: 80rpx;

						.name {
							font-size: 28rpx;
							color: #222222;
						}

						.attr {
							font-size: 24rpx;
							color: #C0C0C0;
						}
					}

					.price-number {
						display: flex;
						align-items: center;
						justify-content: space-between;
						width: 100%;
						height: 60rpx;

						.price {
							display: flex;
							align-items: center;

							text {
								color: #fe3b0f;
								font-weight: bold;
							}

							.min {
								font-size: 26rpx;
							}

							.max {
								font-size: 32rpx;
							}
						}

						.number {
							display: flex;
							align-items: center;

							text {
								font-size: 26rpx;
								color: #222222;
							}
						}
					}

					.tag {
						display: flex;
						align-items: center;
						width: 100%;
						height: 40rpx;

						text {
							padding: 2rpx 12rpx;
							color: #fe3b0f;
							border: 2rpx solid #fe3b0f;
							border-radius: 40rpx;
							font-size: 24rpx;
						}
					}
				}
			}
		}

		.delivery {
			width: 100%;

			.list {
				display: flex;
				align-items: center;
				justify-content: space-between;
				width: 100%;
				height: 80rpx;

				.title {
					font-size: 26rpx;
					color: #555555;
				}

				.content {
					display: flex;
					align-items: center;
					height: 40rpx;

					text {
						font-size: 26rpx;
						color: #222222;
					}

					.iconfont {
						// font-size: 24rpx;
						margin-top: 6rpx;
						margin-left: 10rpx;
					}

					.icon-check {
						font-size: 34rpx;
					}

					input {
						height: 80%;
						font-size: 26rpx;
						color: #222222;
						text-align: right;
					}
				}
			}
		}
	}

	/* 优惠 */
	.discounts-data {
		width: 100%;
		margin: 20rpx auto;
		background-color: #FFFFFF;
		border-radius: 20rpx;

		.discounts {
			padding: 0 4%;

			.list {
				display: flex;
				align-items: center;
				justify-content: space-between;
				width: 100%;
				height: 80rpx;

				.title {
					font-size: 26rpx;
					color: #555555;
				}

				.content {
					display: flex;
					align-items: center;
					height: 40rpx;

					text {
						font-size: 26rpx;
						color: #222222;
					}

					.iconfont {
						// font-size: 24rpx;
						margin-top: 6rpx;
						margin-left: 10rpx;
					}

					.icon-check {
						font-size: 34rpx;
					}

					input {
						height: 80%;
						font-size: 26rpx;
						color: #222222;
						text-align: right;
					}
				}
			}
		}
	}

	/**
	 * 地址提示
	 */
	.address-tips {
		position: fixed;
		left: 0;
		bottom: 100rpx;
		z-index: 100;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100%;
		height: 60rpx;
		padding: 0 4%;
		background-color: #fef2ce;

		text {
			font-size: 26rpx;
			color: #fbbd08;
		}
	}

	/* 订单金额 */
	.order-price {
		width: 100%;
		margin: 20rpx auto;
		background-color: #FFFFFF;
		border-radius: 20rpx;

		.price-list {
			padding: 0 4%;

			.list {
				display: flex;
				align-items: center;
				justify-content: space-between;
				width: 100%;
				height: 80rpx;

				.title {
					display: flex;
					align-items: center;

					text {
						font-size: 26rpx;
						color: #555555;
					}
				}

				.price {
					display: flex;
					align-items: center;

					text {
						font-size: 26rpx;
						font-weight: bold;
						color: #222222;
					}

					.highlight {
						color: #fe3b0f;
					}
				}
			}
		}
	}

	/* 顶部合计提交 */
	.footer-submit {
		position: fixed;
		left: 0;
		bottom: 0;
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: 100%;
		height: 100rpx;
		background-color: #FFFFFF;
		padding: 0 4%;

		.price {
			display: flex;
			align-items: flex-end;

			text {
				font-weight: bold;
				color: #fe3b0f;
			}

			.min {
				font-size: 32rpx;
			}

			.max {
				font-size: 48rpx;
			}
		}

		.submit {


			display: flex;
			align-items: center;
			justify-content: center;
			width: 200rpx;
			height: 70rpx;
			background-color: #2979ff;
			border-radius: 70rpx;

			.slot-content {
				display: flex;
				font-size: 28rpx;
				color: $u-content-color;
				// padding-left: 30rpx;
				justify-content: center;
			}

			text {
				font-size: 26rpx;
				color: #FFFFFF;
			}
		}
	}
</style>
